package com.vlong.town.controller.server.honour;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageHelper;
import com.vlong.town.controller.base.BaseController;
import com.vlong.town.entity.honour.HonourInfo;
import com.vlong.town.service.honour.HonourInfoService;
/**
 * 荣誉成就Rest接口Controller
 * @author Assassin
 */
@RequestMapping("/rest/honour")
@RestController
public class HonourInfoRestController extends  BaseController{
	@Autowired
	private   HonourInfoService  honourInfoService;
	
	/**
     * 查询荣誉成就信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<HonourInfo>
     */
    @GetMapping("/list/{pageNo}/{pageSize}")
	public List<HonourInfo> list(
			 @PathVariable(required=true, value="pageNo") Integer pageNo,
	         @PathVariable(required=true, value="pageSize") Integer pageSize
			) {
    	PageHelper.startPage(getPageNo(pageNo), getPageSize(pageSize));
        PageHelper.orderBy("update_time DESC");
        List<HonourInfo> honourInfoList = this.honourInfoService.queryList(null, null, null);
        return  honourInfoList;
	}
    
    
    /**
     * 小程序
     * 查询荣誉成就信息
     * @param pageNo 当前页码
     * @param pageSize 每页显示记录数
     * @return List<HonourInfo>
     */
    @GetMapping("/listXcx")
	public List<HonourInfo> listXcx() {
        List<HonourInfo> honourInfoList = this.honourInfoService.queryList(null, null, null);
        for (HonourInfo honourInfo : honourInfoList) {
        	Long createTime = honourInfo.getCreateTime();
        	SimpleDateFormat  sdf=new  SimpleDateFormat("yyyy-MM-dd");
        	Date date = new  Date(createTime);
        	String format = sdf.format(date);
        	honourInfo.setCreateDate(format);
		}
        return  honourInfoList;
	}
	
    /**
     * 荣誉成就详情
     * @param 荣誉成就id
     * @return HonourInfo
     */
    @GetMapping("/detail/{id}")
    public HonourInfo detail( @PathVariable(required=true, value="id") Long id) {
    	return  honourInfoService.queryById(id);
    }
    
    
    
	
}
